let scDataIdIndex
function dataCount1(obj) {
    document.getElementById("dropdown").innerHTML = document.getElementById(obj.id).innerHTML
    scDataIdIndex = 0
    getS_CData(1)
}
function gotoPage(page,tableType) {
    switch (tableType){
        case 1:getS_CData(page);
            break;
        case 2:searchBarBtnGetData(groupOption,point_name,page);
            break;
    }

}
function getS_CData(page) {


    $.post("/dataCenter/getS_CData",{page:page},function (result) {
        if (result.flag){

            scDataTableTemplate(result,1)
            document.getElementById("modalCancelBtn").setAttribute("onclick","setDeleteFlag(false)")
            document.getElementById("modalOkBtn").setAttribute("onclick","setDeleteFlag(true)")
            document.getElementById("errBar").style.visibility = "visible"
            document.getElementById("errBar").innerHTML = "点检点位总表"
        }else {
            $("#context").remove()
            $("#pageBar_nav").remove()
            $("#searchBar").remove()
            $("#errBar").remove()
            /*errBar*/
            let errBar_Div = document.createElement("div")
            errBar_Div.setAttribute("id","errBar")
            errBar_Div.className = "errBar"
            errBar_Div.innerHTML = "占位"
            errBar_Div.style.visibility = "hidden"
            document.getElementById("bg_body").appendChild(errBar_Div)
            document.getElementById("errBar").style.visibility = "visible"
            document.getElementById("errBar").innerHTML = result.errorMsg
            document.getElementById("modalCancelBtn").setAttribute("onclick","setDeleteFlag(false)")
            document.getElementById("modalOkBtn").setAttribute("onclick","setDeleteFlag(true)")
        }
    })
}

function scDataTableTemplate(result,tableType) {
    $("#context").remove()
    $("#pageBar_nav").remove()
    $("#searchBar").remove()
    $("#errBar").remove()

    let searchBar_Div = document.createElement("div")
    searchBar_Div.className = "searchBar"
    searchBar_Div.setAttribute("id","searchBar")
    let searchBar_Div_nav = document.createElement("nav")

    let searchBar_Div_nav_ol = document.createElement("ol")
    searchBar_Div_nav_ol.className = "breadcrumb"

    let searchBar_Div_nav_ol_li1 = document.createElement("li")
    searchBar_Div_nav_ol_li1.className = "searchBar_li"

    let searchBar_Div_nav_ol_li_button1 = document.createElement("button")
    searchBar_Div_nav_ol_li_button1.className = "btn btn-primary searchBarBtn"
    searchBar_Div_nav_ol_li_button1.setAttribute("type","button")
    searchBar_Div_nav_ol_li_button1.setAttribute("onclick","searchBarBtn()")
    searchBar_Div_nav_ol_li_button1.innerHTML = "条件查找"

    searchBar_Div_nav_ol_li1.appendChild(searchBar_Div_nav_ol_li_button1)

    let searchBar_Div_nav_ol_li2 = document.createElement("li")
    searchBar_Div_nav_ol_li2.className = "searchBar_li"

    let searchBar_Div_nav_ol_li_input2 = document.createElement("input")
    searchBar_Div_nav_ol_li_input2.className = "form-control searchBarInput"
    searchBar_Div_nav_ol_li_input2.setAttribute("type","text")
    searchBar_Div_nav_ol_li_input2.setAttribute("id","searchBarInput")
    searchBar_Div_nav_ol_li_input2.setAttribute("placeholder","查找点位名")

    searchBar_Div_nav_ol_li2.appendChild(searchBar_Div_nav_ol_li_input2)

    let searchBar_Div_nav_ol_li3 = document.createElement("li")
    searchBar_Div_nav_ol_li3.className = "searchBar_li"

    let searchBar_Div_nav_ol_li3_select = document.createElement("select")
    searchBar_Div_nav_ol_li3_select.className = "custom-select searchBarInput searchBarSelect"
    searchBar_Div_nav_ol_li3_select.setAttribute("id","pram_select_01")

    let searchBar_Div_nav_ol_li3_select_option1 = document.createElement("option")
    searchBar_Div_nav_ol_li3_select_option1.setAttribute("selected","")
    searchBar_Div_nav_ol_li3_select_option1.setAttribute("disabled","")
    searchBar_Div_nav_ol_li3_select_option1.setAttribute("hidden","")
    searchBar_Div_nav_ol_li3_select_option1.innerText = "根据所属查找"

    searchBar_Div_nav_ol_li3_select.appendChild(searchBar_Div_nav_ol_li3_select_option1)

    let group = GetGroup()
    for (const groupElement of group) {
        let searchBar_Div_nav_ol_li3_select_option2 = document.createElement("option")
        searchBar_Div_nav_ol_li3_select_option2.setAttribute("value",groupElement.groupContext)
        searchBar_Div_nav_ol_li3_select_option2.innerText = groupElement.groupAlias
        searchBar_Div_nav_ol_li3_select.appendChild(searchBar_Div_nav_ol_li3_select_option2)
    }
    searchBar_Div_nav_ol_li3.appendChild(searchBar_Div_nav_ol_li3_select)
    searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li1)
    searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li2)
    searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li3)
    searchBar_Div_nav.appendChild(searchBar_Div_nav_ol)
    searchBar_Div.appendChild(searchBar_Div_nav)

    /*errBar*/
    let errBar_Div = document.createElement("div")
    errBar_Div.setAttribute("id","errBar")
    errBar_Div.className = "errBar"
    errBar_Div.innerHTML = "占位"
    errBar_Div.style.visibility = "hidden"

    let pageBar_nav = document.createElement("nav")
    pageBar_nav.setAttribute("aria-label","Page navigation example")
    pageBar_nav.className = "pageBar_nav"
    pageBar_nav.setAttribute("id","pageBar_nav")

    let pageBar_ul = document.createElement("ul")
    pageBar_ul.setAttribute("class","pagination")

    if (result.data.current === 1 || result.data.current < 0) {
        let pageBar_ul_li1 = document.createElement("li")
        pageBar_ul_li1.className = "page-item disabled "

        let pageBar_ul_li_a1 = document.createElement("a")
        pageBar_ul_li_a1.className = "page-link"
        pageBar_ul_li_a1.setAttribute("href","#")
        pageBar_ul_li_a1.setAttribute("aria-label","Previous")

        let pageBar_ul_li_a_span1 = document.createElement("span")
        pageBar_ul_li_a_span1.setAttribute("aria-hidden","true")
        pageBar_ul_li_a_span1.innerHTML = "&laquo;"

        pageBar_ul_li_a1.appendChild(pageBar_ul_li_a_span1)
        pageBar_ul_li1.appendChild(pageBar_ul_li_a1)
        pageBar_ul.appendChild(pageBar_ul_li1)
    }else {
        let pageBar_ul_li1 = document.createElement("li")
        pageBar_ul_li1.className = "page-item"
        pageBar_ul_li1.setAttribute("onclick","gotoPage("+1+","+tableType+")")

        let pageBar_ul_li_a1 = document.createElement("a")
        pageBar_ul_li_a1.className = "page-link"
        pageBar_ul_li_a1.setAttribute("href","#")
        pageBar_ul_li_a1.setAttribute("aria-label","Previous")

        let pageBar_ul_li_a_span1 = document.createElement("span")
        pageBar_ul_li_a_span1.setAttribute("aria-hidden","true")
        pageBar_ul_li_a_span1.innerHTML = "&laquo;"

        pageBar_ul_li_a1.appendChild(pageBar_ul_li_a_span1)
        pageBar_ul_li1.appendChild(pageBar_ul_li_a1)
        pageBar_ul.appendChild(pageBar_ul_li1)
    }



    for (let i = 0; i < result.data.pages; i++) {
        if (result.data.current === (i+1)){
            let pageBar_ul_li = document.createElement("li")
            pageBar_ul_li.className = "page-item active"

            let pageBar_ul_li_a = document.createElement("a")
            pageBar_ul_li_a.className = "page-link"
            pageBar_ul_li_a.setAttribute("href","#")
            pageBar_ul_li_a.innerHTML = (i+1)
            pageBar_ul_li.appendChild(pageBar_ul_li_a)
            pageBar_ul.appendChild(pageBar_ul_li)
        }else {
            let pageBar_ul_li = document.createElement("li")
            pageBar_ul_li.className = "page-item"
            pageBar_ul_li.setAttribute("onclick","gotoPage("+(i+1)+","+tableType+")")
            let pageBar_ul_li_a = document.createElement("a")
            pageBar_ul_li_a.className = "page-link"
            pageBar_ul_li_a.setAttribute("href","#")
            pageBar_ul_li_a.innerHTML = (i+1)
            pageBar_ul_li.appendChild(pageBar_ul_li_a)
            pageBar_ul.appendChild(pageBar_ul_li)
        }

    }
    let pageBar_ul_li2
    let pageBar_ul_li_a2
    let pageBar_ul_li_a_span2
    if (result.data.current === result.data.pages || result.data.current > result.data.pages) {
        pageBar_ul_li2 = document.createElement("li")
        pageBar_ul_li2.className = "page-item disabled"

        pageBar_ul_li_a2 = document.createElement("a")
        pageBar_ul_li_a2.className = "page-link"
        pageBar_ul_li_a2.setAttribute("href","#")
        pageBar_ul_li_a2.setAttribute("aria-label","Next")

        pageBar_ul_li_a_span2 = document.createElement("span")
        pageBar_ul_li_a_span2.setAttribute("aria-hidden","true")
        pageBar_ul_li_a_span2.innerHTML = "&raquo;"
    }else {
        pageBar_ul_li2 = document.createElement("li")
        pageBar_ul_li2.className = "page-item"
        pageBar_ul_li2.setAttribute("onclick","gotoPage("+result.data.pages+","+tableType+")")
        pageBar_ul_li_a2 = document.createElement("a")
        pageBar_ul_li_a2.className = "page-link"
        pageBar_ul_li_a2.setAttribute("href","#")
        pageBar_ul_li_a2.setAttribute("aria-label","Next")

        pageBar_ul_li_a_span2 = document.createElement("span")
        pageBar_ul_li_a_span2.setAttribute("aria-hidden","true")
        pageBar_ul_li_a_span2.innerHTML = "&raquo;"

    }


    let contextSpan = document.createElement("span")
    contextSpan.innerHTML = "共计"+ result.data.total +"条数据"
    contextSpan.className = "contextSpan"



    pageBar_ul_li_a2.appendChild(pageBar_ul_li_a_span2)
    pageBar_ul_li2.appendChild(pageBar_ul_li_a2)
    pageBar_ul.appendChild(pageBar_ul_li2)
    pageBar_ul.appendChild(contextSpan)



    let tableEle = document.createElement("table")
    tableEle.setAttribute("id","pointTable")
    let theadEle = document.createElement("thead")
    let theadTr = document.createElement("tr")

    let contextDiv = document.createElement("div")
    contextDiv.setAttribute("id","context")

    let thEle_select = document.createElement("th")

    let select_div_th = document.createElement("div")
    select_div_th.className = "custom-control custom-switch"



    let select_input_th = document.createElement("input")
    select_input_th.setAttribute("type","checkbox")
    select_input_th.className = "custom-control-input"
    select_input_th.setAttribute("id","ALLCustomSwitch")
    select_input_th.setAttribute("onclick","ALLCustomSwitch(this)")

    let select_label_th = document.createElement("label")
    select_label_th.className = "custom-control-label"
    select_label_th.setAttribute("for","ALLCustomSwitch")
    select_label_th.innerHTML = "全选"

    select_div_th.appendChild(select_input_th)
    select_div_th.appendChild(select_label_th)
    thEle_select.appendChild(select_div_th)
    /*thEle_select.innerHTML = "全选"*/

    let thEle_groupId = document.createElement("th")
    thEle_groupId.innerHTML = "所属"
    let thEle_pointName = document.createElement("th")
    thEle_pointName.innerHTML = "点检点位名"
    let thEle_ID = document.createElement("th")
    thEle_ID.innerHTML = "ID"
    let thEle_createTime = document.createElement("th")
    thEle_createTime.innerHTML = "&#8593 创建时间"
    thEle_createTime.addEventListener("click", function (){
        let index = 1;
    })
    let thEle_updateTime = document.createElement("th")
    thEle_updateTime.innerHTML = "最后更新时间"

    let thEle_action = document.createElement("th")
    thEle_action.innerHTML = "操作"

    theadTr.appendChild(thEle_select)
    theadTr.appendChild(thEle_ID)
    theadTr.appendChild(thEle_pointName)
    theadTr.appendChild(thEle_groupId)
    theadTr.appendChild(thEle_createTime)
    theadTr.appendChild(thEle_updateTime)
    theadTr.appendChild(thEle_action)

    theadEle.appendChild(theadTr)
    tableEle.appendChild(theadEle)
    let tbody = document.createElement("tbody")

    let index = 0
    for (const datum of result.data.records) {
        index++



        let tbodyTr = document.createElement("tr")

        let trTd_select = document.createElement("td")

        let select_div = document.createElement("div")
        select_div.className = "custom-control custom-switch"

        let select_input = document.createElement("input")
        select_input.setAttribute("type","checkbox")
        select_input.className = "custom-control-input"
        select_input.setAttribute("name",index)
        select_input.setAttribute("id","customSwitch"+index)

        let select_label = document.createElement("label")
        select_label.className = "custom-control-label"
        select_label.setAttribute("for","customSwitch"+index)

        select_div.appendChild(select_input)
        select_div.appendChild(select_label)
        trTd_select.appendChild(select_div)

        let trTd_groupId = document.createElement("td")
        trTd_groupId.setAttribute("id","groupID"+index)
        trTd_groupId.innerHTML = datum.groupIdS.length+"项"
        trTd_groupId.onmouseover = function (){
            let groups = [];
            for (const groupIdArrElement of datum.groupIdS) {
                groups.push(groupType(groupIdArrElement))
            }
            trTd_groupId.title = groups.join("\n")
        }
        trTd_groupId.setAttribute("ondblclick","groupIdEdit(this,"+index+")")
        trTd_groupId.setAttribute("onblur","trDeleteEle_cancel()")

        let trTd_pointName = document.createElement("td")
        trTd_pointName.innerHTML = datum.pointName
        trTd_pointName.setAttribute("id","pointName"+index)
        /*trTd_pointName.setAttribute("ondblclick","pointNameEdit(this,"+index+")")*/
        let trTd_ID = document.createElement("td")
        trTd_ID.innerHTML = index
        let trTd_createTime = document.createElement("td")

        trTd_createTime.innerHTML = new Date(datum.createTime).toLocaleDateString()
        let trTd_updateTime = document.createElement("td")
        trTd_updateTime.innerHTML =new Date( datum.updateTime).toLocaleDateString()

        let trTd_action = document.createElement("td")
        let trDailyEle = document.createElement("a")
        trDailyEle.innerHTML = "详细"
        trDailyEle.className = "DailyEle"
        trDailyEle.setAttribute("id","DailyEle" + index)
        trDailyEle.setAttribute("onclick","DailyEle("+index+")")

        let trDeleteEle = document.createElement("a")
        trDeleteEle.innerHTML = "删除"
        trDeleteEle.className = "DeleteEle"
        trDeleteEle.setAttribute("id","trDeleteEle" + index)
        trDeleteEle.setAttribute("onclick","DeleteEle("+index+")")

        trTd_action.appendChild(trDailyEle)
        trTd_action.appendChild(trDeleteEle)

        tbodyTr.appendChild(trTd_select)
        tbodyTr.appendChild(trTd_ID)
        tbodyTr.appendChild(trTd_pointName)
        tbodyTr.appendChild(trTd_groupId)
        tbodyTr.appendChild(trTd_createTime)
        tbodyTr.appendChild(trTd_updateTime)
        tbodyTr.appendChild(trTd_action)

        tbody.appendChild(tbodyTr)

    }
    tableEle.appendChild(tbody)
    contextDiv.appendChild(tableEle)
    pageBar_nav.appendChild(pageBar_ul)

    document.getElementById("bg_body").appendChild(searchBar_Div)
    document.getElementById("bg_body").appendChild(errBar_Div)
    document.getElementById("bg_body").appendChild(contextDiv)
    document.getElementById("bg_body").appendChild(pageBar_nav)

}


function ALLCustomSwitch(obj) {
    let arr_customSwitch = $("[id^='customSwitch']")
    let dailyS = $("[id^='DailyEle']")
    let DailyReviseEleS = $("[id^='DailyReviseEle']")
    if ($(obj).is(":checked") === true) {
        for (const daily of dailyS) {
            document.getElementById(daily.id).style.visibility = "hidden"
        }
        for (const dailyReviseEle of DailyReviseEleS) {
            document.getElementById(dailyReviseEle.id).style.visibility = "hidden"
        }
        for (const arrCustomSwitch of arr_customSwitch) {

            $("#"+arrCustomSwitch.id).prop("checked", true)
        }
    }else {
        for (const arrCustomSwitch of arr_customSwitch) {
            $("#"+arrCustomSwitch.id).prop("checked", false)
        }
        for (const daily of dailyS) {
            document.getElementById(daily.id).style.visibility = "visible"
        }
        for (const dailyReviseEle of DailyReviseEleS) {
            document.getElementById(dailyReviseEle.id).style.visibility = "visible"
        }
    }
}

function DailyEle(index) {
    let pointName = document.getElementById("pointName"+index).innerText
    $.post("/dataCenter/dailySCData",{pointName:pointName,page:1},function (result){
        if (result.flag){
            dailySCDataTable(result)

            document.getElementById("modalCancelBtn").setAttribute("onclick","setDailyDeleteFlag(false)")
            document.getElementById("modalOkBtn").setAttribute("onclick","setDailyDeleteFlag(true)")
        }
    })


}

function dailySCDataTable(result) {

    $("#context").remove()
    $("#pageBar_nav").remove()
    $("#searchBar").remove()
    $("#errBar").remove()

    let searchBar_Div = document.createElement("div")
    searchBar_Div.className = "searchBar"
    searchBar_Div.setAttribute("id", "searchBar")
    let searchBar_Div_nav = document.createElement("nav")

    let searchBar_Div_nav_ol = document.createElement("ol")
    searchBar_Div_nav_ol.className = "breadcrumb"

    let searchBar_Div_nav_ol_li1 = document.createElement("li")
    searchBar_Div_nav_ol_li1.className = "searchBar_li"

    let searchBar_Div_nav_ol_li_button1 = document.createElement("button")
    searchBar_Div_nav_ol_li_button1.className = "btn btn-primary searchBarBtn"
    searchBar_Div_nav_ol_li_button1.setAttribute("type", "button")
    searchBar_Div_nav_ol_li_button1.setAttribute("onclick", "tableBack()")
    searchBar_Div_nav_ol_li_button1.innerHTML = "返回"

    searchBar_Div_nav_ol_li1.appendChild(searchBar_Div_nav_ol_li_button1)

    let searchBar_Div_nav_ol_li2 = document.createElement("li")
    searchBar_Div_nav_ol_li2.className = "searchBar_li"

    let searchBar_Div_nav_ol_li_input2 = document.createElement("input")
    searchBar_Div_nav_ol_li_input2.className = "form-control searchBarInput"
    searchBar_Div_nav_ol_li_input2.setAttribute("type", "text")
    searchBar_Div_nav_ol_li_input2.setAttribute("id", "searchBarInput")
    searchBar_Div_nav_ol_li_input2.setAttribute("placeholder", "查找点位名")

    searchBar_Div_nav_ol_li2.appendChild(searchBar_Div_nav_ol_li_input2)

    let searchBar_Div_nav_ol_li3 = document.createElement("li")
    searchBar_Div_nav_ol_li3.className = "searchBar_li"

    let searchBar_Div_nav_ol_li3_select = document.createElement("select")
    searchBar_Div_nav_ol_li3_select.className = "custom-select searchBarInput searchBarSelect"
    searchBar_Div_nav_ol_li3_select.setAttribute("id", "pram_select_01")

    let searchBar_Div_nav_ol_li3_select_option1 = document.createElement("option")
    searchBar_Div_nav_ol_li3_select_option1.setAttribute("selected", "")
    searchBar_Div_nav_ol_li3_select_option1.setAttribute("disabled", "")
    searchBar_Div_nav_ol_li3_select_option1.setAttribute("hidden", "")
    searchBar_Div_nav_ol_li3_select_option1.innerText = "根据所属查找"

    searchBar_Div_nav_ol_li3_select.appendChild(searchBar_Div_nav_ol_li3_select_option1)

    let group = GetGroup()
    for (const groupElement of group) {
        let searchBar_Div_nav_ol_li3_select_option2 = document.createElement("option")
        searchBar_Div_nav_ol_li3_select_option2.setAttribute("value", groupElement.groupContext)
        searchBar_Div_nav_ol_li3_select_option2.innerText = groupElement.groupAlias
        searchBar_Div_nav_ol_li3_select.appendChild(searchBar_Div_nav_ol_li3_select_option2)
    }
    searchBar_Div_nav_ol_li3.appendChild(searchBar_Div_nav_ol_li3_select)
    searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li1)
    /* searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li2)
     searchBar_Div_nav_ol.appendChild(searchBar_Div_nav_ol_li3)*/
    searchBar_Div_nav.appendChild(searchBar_Div_nav_ol)
    searchBar_Div.appendChild(searchBar_Div_nav)

    /*errBar*/
    let errBar_Div = document.createElement("div")
    errBar_Div.setAttribute("id", "errBar")
    errBar_Div.className = "errBar"
    errBar_Div.innerHTML = "占位"
    errBar_Div.style.visibility = "hidden"

    let pageBar_nav = document.createElement("nav")
    pageBar_nav.setAttribute("aria-label", "Page navigation example")
    pageBar_nav.className = "pageBar_nav"
    pageBar_nav.setAttribute("id", "pageBar_nav")

    let pageBar_ul = document.createElement("ul")
    pageBar_ul.setAttribute("class", "pagination")

    if (result.data.current === 1 || result.data.current < 0) {
        let pageBar_ul_li1 = document.createElement("li")
        pageBar_ul_li1.className = "page-item disabled "

        let pageBar_ul_li_a1 = document.createElement("a")
        pageBar_ul_li_a1.className = "page-link"
        pageBar_ul_li_a1.setAttribute("href", "#")
        pageBar_ul_li_a1.setAttribute("aria-label", "Previous")

        let pageBar_ul_li_a_span1 = document.createElement("span")
        pageBar_ul_li_a_span1.setAttribute("aria-hidden", "true")
        pageBar_ul_li_a_span1.innerHTML = "&laquo;"

        pageBar_ul_li_a1.appendChild(pageBar_ul_li_a_span1)
        pageBar_ul_li1.appendChild(pageBar_ul_li_a1)
        pageBar_ul.appendChild(pageBar_ul_li1)
    } else {
        let pageBar_ul_li1 = document.createElement("li")
        pageBar_ul_li1.className = "page-item"
        pageBar_ul_li1.setAttribute("onclick", "gotoPage(" + 1 + "," + tableType + ")")

        let pageBar_ul_li_a1 = document.createElement("a")
        pageBar_ul_li_a1.className = "page-link"
        pageBar_ul_li_a1.setAttribute("href", "#")
        pageBar_ul_li_a1.setAttribute("aria-label", "Previous")

        let pageBar_ul_li_a_span1 = document.createElement("span")
        pageBar_ul_li_a_span1.setAttribute("aria-hidden", "true")
        pageBar_ul_li_a_span1.innerHTML = "&laquo;"

        pageBar_ul_li_a1.appendChild(pageBar_ul_li_a_span1)
        pageBar_ul_li1.appendChild(pageBar_ul_li_a1)
        pageBar_ul.appendChild(pageBar_ul_li1)
    }


    for (let i = 0; i < result.data.pages; i++) {
        if (result.data.current === (i + 1)) {
            let pageBar_ul_li = document.createElement("li")
            pageBar_ul_li.className = "page-item active"

            let pageBar_ul_li_a = document.createElement("a")
            pageBar_ul_li_a.className = "page-link"
            pageBar_ul_li_a.setAttribute("href", "#")
            pageBar_ul_li_a.innerHTML = (i + 1)
            pageBar_ul_li.appendChild(pageBar_ul_li_a)
            pageBar_ul.appendChild(pageBar_ul_li)
        } else {
            let pageBar_ul_li = document.createElement("li")
            pageBar_ul_li.className = "page-item"
            pageBar_ul_li.setAttribute("onclick", "gotoPage(" + (i + 1) + "," + tableType + ")")
            let pageBar_ul_li_a = document.createElement("a")
            pageBar_ul_li_a.className = "page-link"
            pageBar_ul_li_a.setAttribute("href", "#")
            pageBar_ul_li_a.innerHTML = (i + 1)
            pageBar_ul_li.appendChild(pageBar_ul_li_a)
            pageBar_ul.appendChild(pageBar_ul_li)
        }

    }
    let pageBar_ul_li2
    let pageBar_ul_li_a2
    let pageBar_ul_li_a_span2
    if (result.data.current === result.data.pages || result.data.current > result.data.pages) {
        pageBar_ul_li2 = document.createElement("li")
        pageBar_ul_li2.className = "page-item disabled"

        pageBar_ul_li_a2 = document.createElement("a")
        pageBar_ul_li_a2.className = "page-link"
        pageBar_ul_li_a2.setAttribute("href", "#")
        pageBar_ul_li_a2.setAttribute("aria-label", "Next")

        pageBar_ul_li_a_span2 = document.createElement("span")
        pageBar_ul_li_a_span2.setAttribute("aria-hidden", "true")
        pageBar_ul_li_a_span2.innerHTML = "&raquo;"
    } else {
        pageBar_ul_li2 = document.createElement("li")
        pageBar_ul_li2.className = "page-item"
        pageBar_ul_li2.setAttribute("onclick", "gotoPage(" + result.data.pages + "," + tableType + ")")
        pageBar_ul_li_a2 = document.createElement("a")
        pageBar_ul_li_a2.className = "page-link"
        pageBar_ul_li_a2.setAttribute("href", "#")
        pageBar_ul_li_a2.setAttribute("aria-label", "Next")

        pageBar_ul_li_a_span2 = document.createElement("span")
        pageBar_ul_li_a_span2.setAttribute("aria-hidden", "true")
        pageBar_ul_li_a_span2.innerHTML = "&raquo;"

    }


    let contextSpan = document.createElement("span")
    contextSpan.innerHTML = "共计" + result.data.total + "条数据"
    contextSpan.className = "contextSpan"


    pageBar_ul_li_a2.appendChild(pageBar_ul_li_a_span2)
    pageBar_ul_li2.appendChild(pageBar_ul_li_a2)
    pageBar_ul.appendChild(pageBar_ul_li2)
    pageBar_ul.appendChild(contextSpan)


    let tableEle = document.createElement("table")
    tableEle.setAttribute("id", "pointTable")
    let theadEle = document.createElement("thead")
    let theadTr = document.createElement("tr")

    let contextDiv = document.createElement("div")
    contextDiv.setAttribute("id", "context")

    let thEle_select = document.createElement("th")

    let select_div_th = document.createElement("div")
    select_div_th.className = "custom-control custom-switch"


    let select_input_th = document.createElement("input")
    select_input_th.setAttribute("type", "checkbox")
    select_input_th.className = "custom-control-input"
    select_input_th.setAttribute("id", "ALLCustomSwitch")
    select_input_th.setAttribute("onclick", "ALLCustomSwitch(this)")

    let select_label_th = document.createElement("label")
    select_label_th.className = "custom-control-label"
    select_label_th.setAttribute("for", "ALLCustomSwitch")
    select_label_th.innerHTML = "全选"

    select_div_th.appendChild(select_input_th)
    select_div_th.appendChild(select_label_th)
    thEle_select.appendChild(select_div_th)
    /*thEle_select.innerHTML = "全选"*/

    let thEle_ID = document.createElement("th")
    thEle_ID.innerHTML = "ID"

    let thEle_pointName = document.createElement("th")
    thEle_pointName.innerHTML = "点检点位名"

    let thEle_pointContent = document.createElement("th")
    thEle_pointContent.innerHTML = "点检项"


    let thEle_scFun = document.createElement("th")
    thEle_scFun.innerHTML = "点检方法"
    let thEle_scBenchmark = document.createElement("th")
    thEle_scBenchmark.innerHTML = "点检基准"

    let thEle_pointContentStandard = document.createElement("th")
    thEle_pointContentStandard.innerHTML = "标准图片"

    let thEle_action = document.createElement("th")
    thEle_action.innerHTML = "操作"

    theadTr.appendChild(thEle_select)
    theadTr.appendChild(thEle_ID)
    theadTr.appendChild(thEle_pointName)
    theadTr.appendChild(thEle_pointContent)
    theadTr.appendChild(thEle_scFun)
    theadTr.appendChild(thEle_scBenchmark)
    theadTr.appendChild(thEle_pointContentStandard)
    theadTr.appendChild(thEle_action)

    theadEle.appendChild(theadTr)
    tableEle.appendChild(theadEle)
    let tbody = document.createElement("tbody")

    let index = 0
    for (const datum of result.data.records) {
        index++


        let tbodyTr = document.createElement("tr")

        let trTd_select = document.createElement("td")

        let select_div = document.createElement("div")
        select_div.className = "custom-control custom-switch"

        let select_input = document.createElement("input")
        select_input.setAttribute("type", "checkbox")
        select_input.className = "custom-control-input"
        select_input.setAttribute("name", index)
        select_input.setAttribute("id", "customSwitch" + index)

        let select_label = document.createElement("label")
        select_label.className = "custom-control-label"
        select_label.setAttribute("for", "customSwitch" + index)

        select_div.appendChild(select_input)
        select_div.appendChild(select_label)
        trTd_select.appendChild(select_div)

        let trTd_ID = document.createElement("td")
        trTd_ID.innerHTML = index

        let trTd_pointName = document.createElement("td")
        trTd_pointName.innerHTML = datum.pointName
        trTd_pointName.setAttribute("id","pointName"+index)

        let trTd_pointContent = document.createElement("td")
        trTd_pointContent.setAttribute("id","pointContent"+index)
        trTd_pointContent.setAttribute("name","pointContent")
        trTd_pointContent.setAttribute("ondblclick","dailyEdit(this,"+index+")")
        trTd_pointContent.innerHTML =datum.pointContent


        let trTd_scFun = document.createElement("td")
        trTd_scFun.setAttribute("id","scFun"+index)
        trTd_scFun.setAttribute("name","scFun")
        trTd_scFun.setAttribute("ondblclick","dailyEdit(this,"+index+")")
        trTd_scFun.innerHTML = datum.scFun
        let trTd_scBenchmark = document.createElement("td")
        trTd_scBenchmark.setAttribute("id","scBenchmark"+index)
        trTd_scBenchmark.setAttribute("name","scBenchmark")
        trTd_scBenchmark.setAttribute("ondblclick","dailyEdit(this,"+index+")")
        trTd_scBenchmark.innerHTML =datum.scBenchmark

        let trTd_pointContentStandard = document.createElement("td")
        let staticTempPath = "/Spot_check/TempImage/"
        if (datum.pointContentStandard != null){
            let imgEle = document.createElement("img")
            imgEle.style.height = "40px"
            imgEle.style.width = "70px"
            imgEle.src = staticTempPath + datum.pointContentStandard
            trTd_pointContentStandard.appendChild(imgEle)
        }
        /*trTd_pointContentStandard.innerHTML =datum.pointContentStandard*/

        let trTd_action = document.createElement("td")
        let trDailyEle = document.createElement("a")
        trDailyEle.innerHTML = "修改"
        trDailyEle.className = "DailyEle"
        trDailyEle.setAttribute("id","DailyReviseEle" + index)
        trDailyEle.setAttribute("onclick","DailyReviseEle("+index+")")
        trDailyEle.style.visibility = "hidden"

        let trDeleteEle = document.createElement("a")
        trDeleteEle.innerHTML = "删除"
        trDeleteEle.className = "DeleteEle"
        trDeleteEle.setAttribute("id","DeleteDailyEle" + index)
        trDeleteEle.setAttribute("onclick","DeleteDailyEle("+index+")")

        trTd_action.appendChild(trDailyEle)
        trTd_action.appendChild(trDeleteEle)

        tbodyTr.appendChild(trTd_select)
        tbodyTr.appendChild(trTd_ID)
        tbodyTr.appendChild(trTd_pointName)
        tbodyTr.appendChild(trTd_pointContent)
        tbodyTr.appendChild(trTd_scFun)
        tbodyTr.appendChild(trTd_scBenchmark)
        tbodyTr.appendChild(trTd_pointContentStandard)
        tbodyTr.appendChild(trTd_action)

        tbody.appendChild(tbodyTr)



    }
    tableEle.appendChild(tbody)
    contextDiv.appendChild(tableEle)
    pageBar_nav.appendChild(pageBar_ul)

    document.getElementById("bg_body").appendChild(searchBar_Div)
    document.getElementById("bg_body").appendChild(errBar_Div)
    document.getElementById("bg_body").appendChild(contextDiv)
    document.getElementById("bg_body").appendChild(pageBar_nav)

}

let pointNameArr
let groupIdArr
function DeleteEle(index1) {
    /*if ($(obj).is(":checked") === true) {*/
    timerc = 5
    let indexArr = []
    pointNameArr = []
    groupIdArr = []
    let arr_customSwitch = $("[id^='customSwitch']")
    let i = 0;
    for (const arrCustomSwitch of arr_customSwitch) {
        if ($("#" + arrCustomSwitch.id).is(":checked") === true) {
            i++
            indexArr.push(document.getElementById(arrCustomSwitch.id).getAttribute("name"))
        }
    }
    if (i < 2){
        pointNameArr.push(document.getElementById("pointName"+index1).innerHTML)
        groupIdArr.push(document.getElementById("groupID"+index1).innerHTML)
        console.log("groupID"+index1)
    }else {
        for (const index of indexArr) {
            /*   pointName  groupID*/

            pointNameArr.push(document.getElementById("pointName"+index).innerHTML)
            groupIdArr.push(document.getElementById("groupID"+index).innerHTML)
            console.log("aaa"+pointNameArr)
        }
    }

    $("#exampleModal01").modal("show")

    if (pointNameArr.length > 1){

        document.getElementById("deleteMsg").innerText = "您确定要删除"+pointNameArr[0]+"等"+pointNameArr.length+"条数据吗？"
        add()
    }else {
        console.log(pointNameArr)
        document.getElementById("deleteMsg").innerText = "您确定要删除"+document.getElementById("pointName"+index1).innerHTML +"数据吗？"
    }



}
var timerc = 5; //全局时间变量（秒数）
function add(){
    if (timerc > 0) {


        $("#modalOkBtn").text('等待' + Number(parseInt(timerc % 60 / 10)).toString() + (timerc % 10));

        $("#modalOkBtn").attr("disabled", true);
        timerc--;
        setTimeout("add()", 1000); //设置1000毫秒以后执行一次本函数

    }
    else {
        $("#modalOkBtn").attr("disabled", false);
        $("#modalOkBtn").text('确认');
    };
};


let groupOption
let point_name
function searchBarBtn() {
    groupOption=''
    point_name=''
    groupOption = $("#pram_select_01 option:selected").attr("value")
    point_name = $("#searchBarInput").val()
    if ((groupOption === null || groupOption === "" || groupOption === undefined) && (point_name === null || point_name === "")){
        document.getElementById("errBar").style.visibility = "visible"
        document.getElementById("errBar").innerHTML = "查询条件不能为空！"
    }else {

        searchBarBtnGetData(groupOption,point_name,1)
        document.getElementById("errBar").style.visibility = "visible"
        document.getElementById("errBar").innerHTML = "条件查询数据表"
    }


}
function searchBarBtnGetData(groupOption,point_name,page) {
    $.post("/spot_check/conditionalQueries",{groupOption:groupOption,point_name:point_name,page:page},function (result) {
        if (result.flag){

            scDataTableTemplate(result,2)
            document.getElementById("errBar").style.visibility = "visible"
            document.getElementById("errBar").innerHTML = "条件查询数据表"

        }else {
            document.getElementById("errBar").style.visibility = "visible"
            document.getElementById("errBar").innerHTML = result.errorMsg
        }
    })
}



function setDeleteFlag(flag){
    let deleteFlag = false
    deleteFlag = flag
    if (deleteFlag){
        console.log(pointNameArr)
        /*$.post("/dataCenter/deleteSCData",{pointNameArr:pointNameArr,groupIdArr:groupIdArr},function (result){

        })*/
        $.ajax({
            url: "/dataCenter/deleteSCData",
            type:"post",
            dataType:"json",
            data:{pointNameArr:JSON.stringify(pointNameArr),groupIdArr:JSON.stringify(groupIdArr)},
            success:function (result) {
                if (result){
                    document.getElementById("errBar").style.visibility = "visible"
                    document.getElementById("errBar").innerHTML = "删除成功"
                    if ((groupOption === undefined) ||(point_name === undefined)){
                        getS_CData(1)
                    }else {
                        searchBarBtnGetData(groupOption,point_name,1)
                    }

                }else {
                    document.getElementById("errBar").style.visibility = "visible"
                    document.getElementById("errBar").innerHTML = "删除失败"
                    if ((groupOption === undefined) ||(point_name === undefined)){
                        getS_CData(1)
                    }else {
                        searchBarBtnGetData(groupOption,point_name,1)
                    }
                }
            }
        })
    }else {

        $("#exampleModal01").modal("hide")
    }

}

function tableBack() {
    if ((groupOption === undefined) ||(point_name === undefined)){
        getS_CData(1)
    }else {
        searchBarBtnGetData(groupOption,point_name,1)
    }
}

function DailyReviseEle(){

}
let dailyPointNameArr
let dailyPointContextArr
function DeleteDailyEle(index1){
    timerc = 5
    let indexArr = []
    dailyPointNameArr = []
    dailyPointContextArr = []
    let arr_customSwitch = $("[id^='customSwitch']")
    let i = 0;
    for (const arrCustomSwitch of arr_customSwitch) {
        if ($("#" + arrCustomSwitch.id).is(":checked") === true) {
            i++
            indexArr.push(document.getElementById(arrCustomSwitch.id).getAttribute("name"))
        }
    }
    if (i < 2){
        dailyPointNameArr.push(document.getElementById("pointName"+index1).innerHTML)
        dailyPointContextArr.push(document.getElementById("pointContent"+index1).innerHTML)
        console.log("pointContent"+index1)
    }else {
        for (const index of indexArr) {
            /*   pointName  groupID*/

            dailyPointNameArr.push(document.getElementById("pointName"+index).innerHTML)
            dailyPointContextArr.push(document.getElementById("pointContent"+index).innerHTML)

        }
    }

    $("#exampleModal01").modal("show")

    if (dailyPointNameArr.length > 1){

        document.getElementById("deleteMsg").innerText = "您确定要删除"+dailyPointNameArr[0]+"等"+dailyPointNameArr.length+"条数据吗？"
        add()
    }else {

        document.getElementById("deleteMsg").innerText = "您确定要删除"+document.getElementById("pointName"+index1).innerHTML +"数据吗？"
    }


}

function setDailyDeleteFlag(flag){
    let deleteFlag = false
    deleteFlag = flag
    if (deleteFlag){
        console.log(pointNameArr)
        /*$.post("/dataCenter/deleteSCData",{pointNameArr:pointNameArr,groupIdArr:groupIdArr},function (result){

        })*/
        $.ajax({
            url: "/dataCenter/deleteDailySCData",
            type:"post",
            dataType:"json",
            data:{dailyPointNameArr:JSON.stringify(dailyPointNameArr),dailyPointContextArr:JSON.stringify(dailyPointContextArr)},
            success:function (result) {
                if (result){
                    document.getElementById("errBar").style.visibility = "visible"
                    document.getElementById("errBar").innerHTML = "删除成功"
                    DailyEle(groupOption,point_name,1)


                }else {
                    document.getElementById("errBar").style.visibility = "visible"
                    document.getElementById("errBar").innerHTML = "删除失败"
                    DailyEle(groupOption,point_name,1)
                }
            }
        })
    }else {

        $("#exampleModal01").modal("hide")
    }

}

function DailyEleBtn_ok() {
    let editInputArr = $("[id^='editInput']")
    let valueArr = []

    let i = 0
    for (const editInputArrElement of editInputArr) {
        if ($("#" + editInputArrElement.id).is(":checked") === true) {
            i++
            valueArr.push(document.getElementById(editInputArrElement.id).value)
        }
    }

    if (i > 0){
        let pointName = document.getElementById("pointName"+groupIdEdit_index).innerText
        $.ajax({
            url:"/dataCenter/reversSCDataGroup",
            type:"post",
            dataType:"json",
            data:{groupArr:JSON.stringify(valueArr),pointName:JSON.stringify(pointName)},
            success:function (result){
                if ((groupOption === undefined) ||(point_name === undefined)){
                    getS_CData(1)
                }else {
                    searchBarBtnGetData(groupOption,point_name,1)
                }
            }
        })
    }

}

function trDeleteEle_cancel() {

    if (groupIdEdit_td !== undefined) {
        $("#"+groupIdEdit_td.id).empty()
        groupIdEdit_td.innerText = tdText
        groupIdEdit_td.style.textAlign = "center"

        let DailyEleBtn = document.getElementById("DailyEle"+groupIdEdit_index)
        let trDeleteEle = document.getElementById("trDeleteEle"+groupIdEdit_index)
        DailyEleBtn.innerText = "详细"
        trDeleteEle.innerText = "删除"
        DailyEleBtn.setAttribute("onclick","DailyEle("+groupIdEdit_index+")")
        trDeleteEle.setAttribute("onclick","DeleteEle("+groupIdEdit_index+")")
    }

}
let tdText;
let groupIdEdit_td;
let groupIdEdit_index
function groupIdEdit(obj,index) {
    trDeleteEle_cancel()
    groupIdEdit_index = ""
    tdText=""
    groupIdEdit_td = ""

    groupIdEdit_td = document.getElementById(obj.id)
    groupIdEdit_index = index
    tdText = groupIdEdit_td.innerText
    groupIdEdit_td.innerText = ""
    groupIdEdit_td.style.textAlign = "left"

    let DailyEleBtn = document.getElementById("DailyEle"+index)
    let trDeleteEle = document.getElementById("trDeleteEle"+index)
    DailyEleBtn.innerText = "确定"
    trDeleteEle.innerText = "取消"
    DailyEleBtn.setAttribute("onclick","DailyEleBtn_ok()")
    trDeleteEle.setAttribute("onclick","trDeleteEle_cancel()")



    let group = GetGroup();
    let i = 0
    for (const groupElement of group) {
        i++
        let select_input_th = document.createElement("input")
        select_input_th.setAttribute("type", "checkbox")
        select_input_th.setAttribute("value",groupElement.groupContext)
        select_input_th.className = "editInput"
        select_input_th.setAttribute("id", "editInput"+i)

        let select_label_th = document.createElement("label")
        select_label_th.className = "editLabel"
        select_label_th.innerHTML = groupElement.groupAlias
        let br = document.createElement("br")

        groupIdEdit_td.appendChild(select_input_th)
        groupIdEdit_td.appendChild(select_label_th)
        groupIdEdit_td.appendChild(br)
    }
}
let DailyEdit_pointContent
let DailyEdit_pointName;
let DailyEdit_scFun;
let DailyEdit_scBenchmark;
let dailyEditFlagIndex = 0;
function dailyEdit(obj,index) {
    if (dailyEditFlagIndex === 0) {
        dailyEditFlagIndex = index
    }else {
        if (dailyEditFlagIndex !== index) {
            setErrMsgBar("当前操作不合法！",true)
        }else {
            setErrMsgBar("",false)

            DailyEdit_pointContent = document.getElementById("pointContent" + index).innerText
            let objName = document.getElementById(obj.id).getAttribute("name")
            if (objName === "pointContent") {
                DailyEdit_pointName = ''
                DailyEdit_pointName = document.getElementById(obj.id).innerText

                document.getElementById(obj.id).innerText = ""

                let input = document.createElement("input")
                input.className = "form-control form-control-sm"
                input.setAttribute("type", "text")
                input.setAttribute("id", "pointContentInput" + index)
                document.getElementById(obj.id).appendChild(input)

            } else if (objName === "scFun") {
                DailyEdit_scFun = ''
                DailyEdit_scFun = document.getElementById(obj.id).innerText

                document.getElementById(obj.id).innerText = ""

                let input = document.createElement("input")
                input.className = "form-control form-control-sm"
                input.setAttribute("type", "text")
                input.setAttribute("id", "scFunInput" + index)
                document.getElementById(obj.id).appendChild(input)
            } else if (objName === "scBenchmark") {
                DailyEdit_scBenchmark = ''
                DailyEdit_scBenchmark = document.getElementById(obj.id).innerText

                document.getElementById(obj.id).innerText = ""

                let input = document.createElement("input")
                input.className = "form-control form-control-sm"
                input.setAttribute("type", "text")
                input.setAttribute("id", "scBenchmarkInput" + index)
                document.getElementById(obj.id).appendChild(input)
            }
            /*<input class="form-control" type="text" placeholder="Default input">*/


            let Ok_DailyEditBtn = document.getElementById("DailyReviseEle" + index)
            let Cancel_DailyEditBtn = document.getElementById("DeleteDailyEle" + index)

            Ok_DailyEditBtn.innerText = "确认"
            Ok_DailyEditBtn.style.visibility = "visible"
            Ok_DailyEditBtn.setAttribute("onclick", "DailyEditOkBtn(" + index + ")")
            Cancel_DailyEditBtn.innerText = "取消"
            Cancel_DailyEditBtn.setAttribute("onclick", "DailyEditCancelBtn(" + index + ")")
        }
    }
}

function DailyEditOkBtn(index) {
    dailyEditFlagIndex = 0
    let pointContentInput
    let scFunInput
    let scBenchmarkInput


    let pointContentInputEle = document.getElementById("pointContentInput"+index)
    let scFunInputEle = document.getElementById("scFunInput"+index)
    let scBenchmarkInputEle = document.getElementById("scBenchmarkInput"+index)
    if (pointContentInputEle === null){
        pointContentInput = ""
    }else {
        pointContentInput = pointContentInputEle.value
    }
    if (scFunInputEle === null){
        scFunInput = ""
    }else {
        scFunInput = scFunInputEle.value
    }
    if (scBenchmarkInputEle === null){
        scBenchmarkInput = ""
    }else {
        scBenchmarkInput = scBenchmarkInputEle.value
    }



    console.log(scBenchmarkInput)
    let pointName = document.getElementById("pointName"+index).innerText

    /*$.post("/dataCenter/dailyEdit",{DailyEdit_pointContent:DailyEdit_pointContent,pointName:pointName,pointContentInput:pointContentInput,scFunInput:scFunInput,scBenchmarkInput:scBenchmarkInput},function (result){
            setErrMsgBar(result.errorMsg,true)
    })*/
    $.ajax({
        url:"/dataCenter/dailyEdit",
        type:"post",
        dataType:"json",
        async:false,
        data:{DailyEdit_pointContent:DailyEdit_pointContent,pointName:pointName,pointContentInput:pointContentInput,scFunInput:scFunInput,scBenchmarkInput:scBenchmarkInput},
        success:function (result){
            setErrMsgBar(result.errorMsg,true)
        },
        complete:function (){
            DailyEle(index)
        }
    })


}

function DailyEditCancelBtn(index) {
    dailyEditFlagIndex = 0
    let Ok_DailyEditBtn = document.getElementById("DailyReviseEle"+index)
    let Cancel_DailyEditBtn = document.getElementById("DeleteDailyEle"+index)

    Ok_DailyEditBtn.innerText = "修改"
    Ok_DailyEditBtn.style.visibility = "hidden"
    Ok_DailyEditBtn.setAttribute("onclick","DailyReviseEle("+index+")")
    Cancel_DailyEditBtn.innerText = "删除"
    Cancel_DailyEditBtn.setAttribute("onclick","DeleteDailyEle("+index+")")

    let pointName = document.getElementById("pointContent"+index)
    let scFun = document.getElementById("scFun"+index)
    let scBenchmark = document.getElementById("scBenchmark"+index)

    pointName.innerText = DailyEdit_pointName
    scFun.innerText = DailyEdit_scFun
    scBenchmark.innerText = DailyEdit_scBenchmark
}

function setErrMsgBar(errMsg,flag) {
    if (flag){
        document.getElementById("errBar").innerText = errMsg
        document.getElementById("errBar").style.visibility = "visible"
    }else {
        document.getElementById("errBar").style.visibility = "hidden"
    }

}



